/**
 * Created by ZFL on 2017/9/25.
 */
var vm=new Vue({
    el:'#revenueDetails',
    data:{
        sStamp:'',
        eStamp:'',
        orderList:[],   //订单列表
        ordersStatus:'',
        date:{},
        array:[1,2,3],
        stamp:0,
        totalSales:0,     //总销售额
        totalCommission:0      //总佣金
    },
    methods:{

    }
})
Vue.filter('price',function(value){
    return divideNumber(value,100);
})
var startTime='';
var endTime=''
function searchOrders(){
    startTime=$('#start').val();
    startTime=startTime.replace(/\//g, "-");
    endTime=$('#end').val();
    endTime=endTime.replace(/\//g, "-");
    console.log(startTime);
    console.log(endTime);
    if(startTime!=''&&endTime==''){
        YDUI.dialog.toast('请输入结束时间', 'none', 1000);
    }else if(startTime==''&&endTime!=''){
        YDUI.dialog.toast('请输入开始时间', 'none', 1000);
    }else if(startTime==''&&endTime==''){
        YDUI.dialog.toast('请输入时间', 'none', 1000);
    }else{
        getOrder();
    }


}

function getStartTime(){
    startTime=$('#start').val();
    startTime=startTime.replace(/\//g, "-");
    console.log(startTime)
    console.log(1)
}

function appInit(){
    PageInit();
}
function PageInit(){
    infiniteSroll()
    getOrder();


}
var pageNum=1;
var pageSize=10;
var loading=false;




function getOrder(){
    $.ajaxHandler({
        model:function(){
            var obj={};
            obj.startTime=startTime;
            obj.endTime=endTime;
            obj.userId= $.getPara('userId');
            obj.pageNum=pageNum;
            obj.pageSize=10;
            return obj;
        },
        visibleTime: 0,
        dataType: "json",
        approve: true,
        api: 'yg_baijiaapp/statistics/getRevenueBreakDown',
        success:function(res){
            if(res.code===10000){
                var data=res.data;
                if(data.orderList.length>0) {
                    // 加载数据
                    loading = false;
                    data.orderList.forEach(function (item, index) {
                        var date = item.createTime;
                        date = new Date(Date.parse(date.replace(/-/g, "/")));
                        date = date.getTime();
                        item.stamp = date;
                        vm.orderList.push(item)

                    })
                }else {
                    //YDUI.dialog.toast('无更多数据',1000);
                    $(document.body).destroyInfinite();
                }
                vm.totalSales = data.totalSales;
                vm.totalCommission = data.totalCommission;


            }
        }
    })
}



//滚动加载信息
function infiniteSroll() {
    $("body").infinite().on("infinite", function () {
        if (loading) return;
        loading = true;
        pageNum++;

        $('.weui-infinite-scroll-box').show();
        setTimeout(function () {
            loading = false;
            $('.weui-infinite-scroll-box').hide();
            getOrder()
        }, 1500);   //模拟延迟
    });
}


var start = {
    elem: '#start',
    format: 'YYYY/MM/DD',
    min:0, //设定最小日期为当前日期  
    max: '2099-06-16', //最大日期  
    istime: true,
    istoday: false,
    choose: function(datas){
        end.min = datas; //开始日选好后，重置结束日的最小日期  
        end.start = datas //将结束日的初始值设定为开始日  
    }
};
var end = {
    elem: '#end',
    format: 'YYYY/MM/DD',
    min: laydate.now(),
    max: '2099-06-16',
    istime: true,
    istoday: false,
    choose: function(datas){
        start.max = datas; //结束日选好后，重置开始日的最大日期  
    }
};
laydate(start);
laydate(end); 